﻿using Demo.Models;
using FluentNHibernate.AutoMap;
using FluentNHibernate.Cfg.Db;
using NHibernate.Dialect;

namespace Demo.Mapping
{
	public class MappingHelper
	{
		public static IPersistenceConfigurer GetConnectionConfiguration(string connString)
		{
			return new MyConfig(connString);
		}

		public static AutoPersistenceModel GetMapper()
		{
			return AutoPersistenceModel.MapEntitiesFromAssemblyOf<Post>().WithConvention(convention =>
			                                                                             	{
			                                                                             		convention.IdConvention =
			                                                                             			x =>
			                                                                             			x.Access.
			                                                                             				AsReadOnlyPropertyThroughCamelCaseField
			                                                                             				();
			                                                                             	});
		}
	}

	public class MyConfig : SQLiteConfiguration
	{
		public MyConfig(string dbFilePath)
		{
			ConnectionString(x => x.Is(dbFilePath)).Dialect(typeof (SQLiteDialect).FullName);
		}
	}
}